#include "QR.h"
#include "SVD.h"
#include <Windows.h>
using namespace std;
int main()
{
	//
	Matrix mat,U,VT,V,Sigma;
	//mat.SetDim(2, 3);
	//mat(0, 0) = 1;
	//mat(0, 1) = 2;
	//mat(0, 2) = -1;
	//mat(1, 0) = 2;
	//mat(1, 1) = 4;
	//mat(1, 2) = -2;
	
	//mat.SetDim(2, 3);
	//mat(0, 0) = 3;
	//mat(0, 1) = 4;
	//mat(0, 2) = 5;
	//mat(1, 0) = 2;
	//mat(1, 1) = 1;
	//mat(1, 2) = 7;

	mat.SetDim(3, 2);
	mat(0, 0) = 1;
	mat(0, 1) = -1;
	mat(1, 0) = 3;
	mat(1, 1) = -3;
	mat(2, 0) = -3;
	mat(2, 1) = 3;

	mat.SetDim(4, 5);
	mat(0, 0) = 1.3;
	mat(0, 1) = -0.2;
	mat(0, 2) = 0.8;
	mat(0, 3) = -1.1;
	mat(0, 4) = 0.4;
	
	mat(1, 0) = -0.5;
	mat(1, 1) = 2.1;
	mat(1, 2) = 1.4;
	mat(1, 3) = 0.3;
	mat(1, 4) = -0.9;
	
	mat(2, 0) = 0.7;
	mat(2, 1) = -1.2;
	mat(2, 2) = 0.6;
	mat(2, 3) = 1.5;
	mat(2, 4) = -0.3;

	mat(3, 0) = -0.8;
	mat(3, 1) = 0.5;
	mat(3, 2) = -1.3;
	mat(3, 3) = 0.2;
	mat(3, 4) = 1.7;

	mat.Dump(cout, "init mat:");
	
	//Matrix matRREF;
	//::GetMatrixRREF(mat, matRREF);
	::SVD(mat, U, Sigma, VT);

	U.Dump(cout, "U");
	::GetTransMatrix(VT, V);
	VT.Dump(cout, "VT");
	V.Dump(cout, "V");
	Sigma.Dump(cout, "Sigma");
	getchar();
	SquareMatrix A,Q,R;
	A.SetDim(3);

	A(0,0) = 1;
	A(0,1) = 29;
	A(0,2) = -20;

	A(1, 0) = 66;
	A(1, 1) = 15;
	A(1, 2) = 34;
	
	A(2, 0) = 98;
	A(2, 1) = 100;
	A(2, 2) = 43;

	A.Dump();
	std::vector<double> eigenValues;
	//QR(A,Q,R);
	DWORD sta = ::GetTickCount();
	for (int i = 0; i < 1000; i++)
	{
		::GetEigenValuesByQR(A, eigenValues);
	}
	DWORD end = ::GetTickCount();
	cout << "end-sta=" << (end - sta) << "ms" << endl;
	//Q.Dump();
	//R.Dump();
	getchar();
}